package com.goat.model.element;

import javax.swing.*;
import java.awt.*;

/**
 * 玩家子弹类：由player对象创建并调用
 */
public class PlayShoter extends BaseElement{
    public static int count=0;
    //子弹的特有属性
    private int attack=1;
    private int speed=3;
    private String direct;

    public PlayShoter(){}

    private PlayShoter(int x, int y, int w, int h, ImageIcon imageIcon) {
        super(x, y, w, h, imageIcon);
    }

    /*public static PlayShoter createPlayShoter(){

    }*/

    @Override
    public void showElement(Graphics g) {
        g.fillOval(getX(),getY(),getW(),getW() );
    }

    @Override
    protected void move() {
        //改变数据
        //然后主线程调用，会不断的改变
        if(getX()>900||getX()<0||getY()<0||getY()>600){
            setLive(false);//子弹销毁
            return;
        }
        switch (direct){
            case "up":setY(getY()-speed);break;
            case "left":setX(getX()-speed);break;
            case "right":setX(getX()+speed);break;
            case "down":setY(getY()+speed);break;
        }
    }

    @Override
    public BaseElement createElement(String str) {
        setW(3);setH(3);
        String[] s1 = str.split(",");
        for (String s :s1) {
            String[] split = s.split(":");
            switch (split[0]){
                case "x":setX(Integer.parseInt(split[1]));break;
                case "y":setY(Integer.parseInt(split[1]));break;
                case "direct":direct=split[1];break;
            }
        }
        return this;
    }

    //子弹不需要死亡动画
    /*
    public void die() {//死亡也是对象

    }*/

    //演示主线程传入时间gameTime的使用

    int myTime=0;
    @Override
    protected void updateImage(int gameTime) {
        if(gameTime-myTime>20){
            myTime=gameTime;
            setW(getW()+3);
            setH(getH()+3);
        }
    }
}
